home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 6.4 KB | 268 lines | [TEXT/MPS ] |
- /*
- File: VirtualDataForkOnlyFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __VIRTUALMACFILE__
- #include "VirtualMacFile.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __VIRTUALRAMORDISKFILE__
- #include "VirtualRamOrDiskFile.h"
- #endif
-
- #ifndef __VIRTUALDATAFORKONLYFILE__
- #include "VirtualDataForkOnlyFile.h"
- #endif
-
- #ifndef __VIRTUALFILE__
- #include "VirtualFile.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #pragma segment TVirtualDataForkOnlyFile
-
- /***********************************|****************************************/
-
- TVirtualDataForkOnlyFile::TVirtualDataForkOnlyFile(const Str31 fileName, OSType creator, OSType type):
- TVirtualMacFile (),
- fDataFile ( new TVirtualRamOrDiskFile () ),
- fCreationDate ( NowDateTime () ),
- fModificationDate ( NowDateTime() ),
- fOpenCount ( 0 )
- {
- fSpec.vRefNum = -1;
- fSpec.parID = 2;
- SetFileName(fileName);
-
- fFinderInfo.fdType = type;
- fFinderInfo.fdCreator = creator;
- fFinderInfo.fdFlags = 0;
- fFinderInfo.fdLocation.h = fFinderInfo.fdLocation.v = 0;
- fFinderInfo.fdFldr = 0;
-
- fDataFile->RegisterReference();
- }
-
- /***********************************|****************************************/
-
- TVirtualDataForkOnlyFile::TVirtualDataForkOnlyFile(const Str31 fileName, TVirtualFile* dataFile, OSType creator, OSType type ):
- TVirtualMacFile (),
- fDataFile ( dataFile ),
- fCreationDate ( NowDateTime () ),
- fModificationDate ( NowDateTime() ),
- fOpenCount ( 0 )
- {
- fSpec.vRefNum = -1;
- fSpec.parID = 2;
- SetFileName(fileName);
-
- fFinderInfo.fdType = type;
- fFinderInfo.fdCreator = creator;
- fFinderInfo.fdFlags = 0;
- fFinderInfo.fdLocation.h = fFinderInfo.fdLocation.v = 0;
- fFinderInfo.fdFldr = 0;
-
- fDataFile->RegisterReference();
- }
-
- /***********************************|****************************************/
-
- TVirtualDataForkOnlyFile::~TVirtualDataForkOnlyFile()
- {
- fDataFile->UnregisterReference();
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::Open ()
- {
- fOpenCount++;
- if (fOpenCount == 1) {
- fDataFile->SetPosition(fsFromStart, 0);
- }
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::Close ()
- {
- if (fOpenCount <= 1) {
- fOpenCount = 0;
- }
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::ReadData (void* buffer,long& count,TVirtualMacFile::ForkType whichFork)
- { OSErr err;
- if (whichFork == kData)
- err = fDataFile->ReadData (buffer,count);
- else
- err = (count > 0) ? eofErr : noErr;
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::WriteData (const void* buffer, long& count, TVirtualMacFile::ForkType whichFork)
- { OSErr err;
- if (whichFork == kData)
- err = fDataFile->WriteData (buffer,count);
- else
- err = (count > 0) ? posErr : noErr;
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::SetEnd (long logEof, TVirtualMacFile::ForkType whichFork)
- { OSErr err;
- if (whichFork == kData)
- err = fDataFile->SetEnd ( logEof );
- else
- err = (logEof != 0) ? posErr : noErr;
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::GetEnd (long& logEof, TVirtualMacFile::ForkType whichFork) const
- { OSErr err;
- if (whichFork == kData)
- err = fDataFile->GetEnd ( logEof );
- else {
- logEof = 0;
- err = noErr;
- }
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::SetPosition (short posMode, long posOff, TVirtualMacFile::ForkType whichFork)
- {
- OSErr err;
- if (whichFork == kData)
- err = fDataFile->SetPosition (posMode,posOff);
- else {
- err = posErr;
- if (posMode == fsFromStart)
- err = (posOff == 0) ? noErr : posErr;
- else if (posMode == fsFromMark)
- err = (posOff == 0) ? noErr : posErr;
- else if (posMode == fsFromLEOF)
- err = (posOff == 0) ? noErr : posErr;
- }
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::GetPosition (long& filePos, TVirtualMacFile::ForkType whichFork) const
- {
- OSErr err;
- if (whichFork == kData)
- err = fDataFile->GetPosition ( filePos );
- else {
- filePos = 0;
- err = noErr;
- }
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::SetFinderInfo (const FInfo& finderInfo)
- {
- fFinderInfo = finderInfo;
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::GetFinderInfo (FInfo& finderInfo) const
- {
- finderInfo = fFinderInfo;
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::GetDate (unsigned long& dateTime,TVirtualMacFile::WhichDateType whichDate) const
- {
- if (whichDate == kCreationDate)
- dateTime = fCreationDate;
- else
- dateTime = fModificationDate;
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::SetDate (unsigned long dateTime,TVirtualMacFile::WhichDateType whichDate)
- {
- if (whichDate == kCreationDate)
- fCreationDate = dateTime;
- else fModificationDate = dateTime;
-
- return noErr;
- }
-
- /***********************************|****************************************/
-
- void TVirtualDataForkOnlyFile::SetUserRef(long ref)
- {
- fDataFile->SetUserRef(ref);
- }
-
- /***********************************|****************************************/
-
- long TVirtualDataForkOnlyFile::GetUserRef() const
- {
- return fDataFile->GetUserRef();
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::SetSpec ( const FSSpec& spec )
- {
- fSpec = spec;
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualDataForkOnlyFile::GetSpec ( FSSpec& spec ) const
- {
- spec = fSpec;
- return noErr;
- }
-
- /***********************************|****************************************/
-